import { userLogin } from "../api/user"
import router from "../router"


export default {
    namespaced: true,
    state: () => ({
        userInfo: null,
    }),
    mutations: {
        initUserInfoMut(state, info) { //初始化状态机中的state数据包
            state.userInfo = info;
        }
    },
    actions: {
        userLoginAct(context, { obj, target }) {
            userLogin(obj).then(res => {
                console.log(res);
                context.commit('initUserInfoMut', res.data.data) //把响应信息写入状态机
                localStorage.setItem('userInfo', JSON.stringify(res.data.data)) //把响应信息写入本地存储
                if (res.data.code === 111) {
                    router.push(target) //可以替代组件中的this.$router.push
                    this.show = false
                }
            })
        }
    }
}